import { resources, assetManager, SpriteAtlas } from "cc";
import { ResCacheAsset } from "./ResCacheAsset";


export class ResCacheAtlas extends ResCacheAsset<SpriteAtlas> {

    protected onLoadRes() {
        let url = this.path;
        resources.load(url, SpriteAtlas, (error: any, asset: SpriteAtlas) => {
            if (error) {
                console.error(`加载本地精灵图片失败：${url}`);
                console.error(error);
            }
            this.loadFinish(asset);
        });
    }

    // public check(now: number): boolean {
    //     return false;
    // }

    public spawn(name?: string): any {
        this.ref++;
        this.tick = Date.now();
        return this.asset;
    }

    public unSpawn(obj?: any) {
        this.ref--;
        this.tick = Date.now();
    }

    public unSpawnAll(name: string) {
        this.ref = 0;
        this.tick = Date.now();
    }
}